package pl.enigmatic.math;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;


public abstract class MapArray<K, V> extends ArrayList<V> {

	private final Map<K, V> map = new HashMap<K, V>();

	/** */
	private static final long serialVersionUID = 1L;

	protected abstract K projectKey(V value);

	@Override
	public boolean add(final V value) {
		map.put(projectKey(value), value);
		return super.add(value);
	}

	public boolean containsKey(final Object key) {
		return map.containsKey(key);
	}

	public Set<Entry<K, V>> entrySet() {
		return map.entrySet();
	}

	public V get(final K key) {
		return map.get(key);
	}

	public Set<K> keySet() {
		return map.keySet();
	}

}
